
import { createStore, combineReducers } from 'redux';

// 3. 引入模块  购物车模块reducer
import CartReducer from './cart'
import { getJSDocReturnType } from 'typescript';

// 4. 合并 reducer
const reducer = combineReducers({
  cart: CartReducer
})

// 1. 创建仓库
const store = createStore(reducer);
// 6. 订阅仓库
store.subscribe(() =>  {
  const state = store.getState()
  // 将购物车数据存储本地存储
  localStorage.setItem('cartList', JSON.stringify(state.cart.cartList))
  
  console.log('更新后的购物车数据', state.cart.cartList)
})

// 5. 定义仓库类型
export type RootState = ReturnType<typeof store.getState>

// 2. 抛出
export default store


// 1  number